package com.pic.mgt.haishin;

import org.apache.commons.lang.StringUtils;

import com.pic.mgt.config.ConfigBean;
import com.pic.mgt.config.ConfigurationException;

/**
 * [Bean:存放配信參數設定值]
 * @author 洪政緯
 */
public class HaishinConfigBean implements ConfigBean {
	// Path 設定值
	private String haishinInbox;
	private String haishinOutbox;
	private String haishinOutboxPublic;
	
	// System 設定值
	private String appintedHaishinType;  // 指示配信字元
	private String generalHaishinType;   // 一般配信字元
	
	/**
	 * 利用建構式來注入參數，不使用Setter。
	 * 主要原因是不允許散自變更設定值，如要變更則表示需從設定檔做變更，
	 * 並再建立一個新的 HaishinConfigBean
	 * @param haishinInbox
	 * @param haishinInboxScheduling
	 * @param haishinBackup
	 * @param haishinBackupBad
	 * @param hainshinOutbox
	 * @param haishinOutboxPublic
	 *  
	 * @param appintedHaishin  指示配信型態字元
	 * @param generalHaishin   一般配信型態字元
	 */
	HaishinConfigBean(String haishinInbox,
					  String hainshinOutbox,
					  String haishinOutboxPublic,
					  String appintedHaishinType,
					  String generalHaishinType
					  ) {	
		// haishin path config
		this.haishinInbox = haishinInbox;
		this.haishinOutbox = hainshinOutbox;
		this.haishinOutboxPublic = haishinOutboxPublic;	
		
		// haishin system config
		this.appintedHaishinType = appintedHaishinType.trim();
		this.generalHaishinType = generalHaishinType.trim();
	}
	
	/**
	 * 驗證參數設定輸入是否正確(如:空值)
	 * @throws ConfigurationException
	 */
	// TODO 完成各設定值的 Check 動作
	public void checkConfig() throws ConfigurationException {
		ConfigurationException exception =
			new ConfigurationException(
					"Haishin configuration setting error: can't be empty.");
		
		// 檢查參數設定是否為null或empty
		if (StringUtils.isBlank(this.haishinInbox)){throw exception;}		
		if (StringUtils.isBlank(this.haishinOutbox)){throw exception;}
		if (StringUtils.isBlank(this.haishinOutboxPublic)){throw exception;}
		
		exception = null;
	}	

	public String getApInbox() {
		return haishinInbox;
	}

	public String getFtpOutbox() {
		return haishinOutbox;
	}

	public String getFtpOutboxPublic() {
		return haishinOutboxPublic;
	}

	public String getAppintedHaishinType() {
		return appintedHaishinType;
	}

	public String getGeneralHaishinType() {
		return generalHaishinType;
	}
}
